//钥匙和房间
class Solution {
public:
    vector<bool>used;
    bool canVisitAllRooms(vector<vector<int>>& rooms) 
    {
        int n=rooms.size();
        used.resize(n,false);
        dfs(rooms,0);
        for(auto e:used)
        {
            if(!e) return false;
        }
        return true;
    }
    void dfs(vector<vector<int>>& rooms,int index)
    {
        if(used[index]) return;
        used[index]=true;
        vector<int>key=rooms[index];
        for(auto e:key)
        {
            dfs(rooms,e);
        }
    }
};